<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>骡窝窝系统管理平台</title>
    <#include "../common/header.ftl"/>
    <script type="text/javascript" src="/js/plugins/My97DatePicker/WdatePicker.js"></script>
</head>

<body>
<div class="container">
<#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-3">
		<#assign currentMenu = "strategyTravel" />
        <#include "../common/menu.ftl" />
        </div>
        <div class="col-sm-9">
            <div class="page-header">
                <h3>大家都在看</h3>
            </div>
            <div class="row">
                <!-- 提交分页的表单 -->
                <form id="searchForm" class="form-inline" method="post" action="/strategyTravel/queryByStrategyId.do")
                .do">
                    <input type="hidden" name="currentPage" id="currentPage" value="1"/>
                    <div class="form-group">
                        <label>攻略搜索</label>
                        <select id="searchStrategy" class="form-control"  name="strategyId">
                        </select>
                        <button id="query" type="button" class="btn btn-success"><i class="icon-search"></i>查询</button>
                        <a href="javascript:void(-1);" class="btn btn-success inputStrategyTravel">
                            <span class="glyphicon glyphicon-plus"></span>添加关联
                        </a>
                    </div>
                </form>
            </div>
            <div class="row">
                <table class="table">
                    <thead>
                    <tr>
                        <th>序号</th>
                        <th>关联游记</th>
                        <th></th>
                        <th></th>
                    </tr>

                    </thead>
                    <tbody>
					<#list pageInfo.list as entity>
                    <tr>
                        <td>${entity_index +  1}</td>
                        <td>${entity.title!""}</td>
                        <td><a class="seeTravel" data-id="${entity.id}">查看文章详情</a></td>
                        <td><a class="delete" data-json='{"strategyId":${(qo.strategyId!)},"travelId":${entity.id}}'>删除</a></td>
                    </tr>
					</#list>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
<div id="strategyTravelModal" class="modal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">编辑/增加</h4>
            </div>
            <div class="modal-body">
                <form id="strategyTravelForm" class="form-horizontal" method="post" action="/strategyTravel/save.do">
                    <input id="strategyTravelId" type="hidden" name="id" />
                    <input id="reset" type="reset" style="display: none"/>

                    <div class="form-group">
                        <label class="col-sm-4 control-label">所属攻略</label>
                        <div class="col-sm-6">
                            <select id="strategyId" class="form-control"  name="strategyId" >
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">关联游记</label>
                        <div class="col-sm-6">
                            <select id="travelId" class="form-control"  name="travelId">
                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <a href="javascript:void(0);" class="btn btn-success" id="saveStrategyTravelBtn" aria-hidden="true">保存</a>
                <a href="javascript:void(0);" class="btn" data-dismiss="modal" aria-hidden="true">关闭</a>
            </div>
        </div>
    </div>
</div>

<script>
    var template = "";
    $("#query").click(function () {
        $("#searchForm").submit();
    });


    $(".inputStrategyTravel").click(function () {
        $("#strategyId").html(template);
        $("#strategyId").val($("#searchStrategy").val()).prop("disabled",true);
        $.get("/strategyTravel/queryTravel.do",function (data) {
            var temp = "";
            $.each(data,function (index, ele) {
                temp += '<option value="'+ele.id+'">'+ele.title+'</option>';
            });
            $("#travelId").html(temp);
            $("#strategyTravelModal").modal("show");
        });

    });


    $("#saveStrategyTravelBtn").click(function () {
        $("#strategyId").attr("disabled",false);
        $("#strategyTravelForm").ajaxSubmit(function (data) {
            window.location.reload();
        });
    });
    $.get("/strategyCatalog/listAll.do",function (data) {
        var temp = "";
        $.each(data,function (index,ele) {
            temp += "<option value="+ele.id+">"+ele.title+"</option>"
        });
        $("#searchStrategy").html(temp);
        $("#searchStrategy").val("${(qo.strategyId)!}");
        template = temp;
        stratrgyId = "${(qo.strategyId)!}";
    });

    $(".seeTravel").click(function () {
        window.location.href = "/travelRelease/list.do?travelId="+$(this).data("id");

    });

    $(".delete").click(function () {
        var json = $(this).data("json");
        $.get("/strategyTravel/delete.do",{"strategyId":json.strategyId,"travelId":json.travelId},function () {
            window.location.reload();
        })
    });

</script>
</body>
</html>